package com.authorization.project.authorization.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.authorization.framework.aspectj.lang.annotation.Log;
import com.authorization.framework.aspectj.lang.enums.BusinessType;
import com.authorization.project.authorization.domain.AuthorizationHistory;
import com.authorization.project.authorization.service.IAuthorizationHistoryService;
import com.authorization.framework.web.controller.BaseController;
import com.authorization.framework.web.domain.AjaxResult;
import com.authorization.common.utils.poi.ExcelUtil;
import com.authorization.framework.web.page.TableDataInfo;

/**
 * 授权注册信息Controller
 * 
 * @author 李晓雷
 * @date 2020-04-26
 */
@RestController
@RequestMapping("/authorization/history")
public class AuthorizationHistoryController extends BaseController
{
    @Autowired
    private IAuthorizationHistoryService authorizationHistoryService;

    /**
     * 查询授权注册信息列表
     */
    @PreAuthorize("@ss.hasPermi('authorization:history:list')")
    @GetMapping("/list")
    public TableDataInfo list(AuthorizationHistory authorizationHistory)
    {
        startPage();
        List<AuthorizationHistory> list = authorizationHistoryService.selectAuthorizationHistoryList(authorizationHistory);
        return getDataTable(list);
    }

    /**
     * 导出授权注册信息列表
     */
    @PreAuthorize("@ss.hasPermi('authorization:history:export')")
    @Log(title = "授权注册信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AuthorizationHistory authorizationHistory)
    {
        List<AuthorizationHistory> list = authorizationHistoryService.selectAuthorizationHistoryList(authorizationHistory);
        ExcelUtil<AuthorizationHistory> util = new ExcelUtil<AuthorizationHistory>(AuthorizationHistory.class);
        return util.exportExcel(list, "history");
    }

    /**
     * 获取授权注册信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('authorization:history:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(authorizationHistoryService.selectAuthorizationHistoryById(id));
    }

    /**
     * 新增授权注册信息
     */
    @PreAuthorize("@ss.hasPermi('authorization:history:add')")
    @Log(title = "授权注册信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AuthorizationHistory authorizationHistory)
    {
        return toAjax(authorizationHistoryService.insertAuthorizationHistory(authorizationHistory));
    }

    /**
     * 修改授权注册信息
     */
    @PreAuthorize("@ss.hasPermi('authorization:history:edit')")
    @Log(title = "授权注册信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AuthorizationHistory authorizationHistory)
    {
        return toAjax(authorizationHistoryService.updateAuthorizationHistory(authorizationHistory));
    }

    /**
     * 删除授权注册信息
     */
    @PreAuthorize("@ss.hasPermi('authorization:history:remove')")
    @Log(title = "授权注册信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(authorizationHistoryService.deleteAuthorizationHistoryByIds(ids));
    }
}
